package com.flyoil.petromp.mvp_m.CourseDetailModel;

import com.flyoil.petromp.Constant.ConstantNetworkCode;
import com.flyoil.petromp.apiservice.OnObserverRetrofitResetCallBack;
import com.flyoil.petromp.base.BaseEntity;
import com.flyoil.petromp.base.BaseModel;
import com.flyoil.petromp.entity.entity_course_detail.GoodsDemandDetailEntity;
import com.flyoil.petromp.entity.entity_order.MapListEntity;
import com.flyoil.petromp.mvp_p.Listener.OnPresenterListener;
import com.flyoil.petromp.mvp_p.Listener.OrderGoodsMessageListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by songzhiyin on 2017/11/1.
 * 物资审批单明细详情界面数据处理类
 */

public class GoodsApproveDetailModel implements BaseModel {
    @Override
    public void loadNetworkData(Map<String, Object> map, final OnPresenterListener onPresenterListener) {
        httpModel.getCourseGoodsDemandDetail(map, new OnObserverRetrofitResetCallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity model) {
                super.onSuccess(model);
                if (ConstantNetworkCode.SuccedCode != model.getCode()) {
                    onPresenterListener.onsucced(null);
                }
                GoodsDemandDetailEntity goodsDemandDetailEntity = null;
                if (model instanceof GoodsDemandDetailEntity) {
                    goodsDemandDetailEntity = (GoodsDemandDetailEntity) model;
                }
                if (goodsDemandDetailEntity != null && goodsDemandDetailEntity.getData() != null) {
                    GoodsDemandDetailEntity.DataBean dataBean = goodsDemandDetailEntity.getData();
                    OrderGoodsMessageListener listener = (OrderGoodsMessageListener) onPresenterListener;
                    List<MapListEntity> mapListEntities = new ArrayList<>();
                    mapListEntities.add(new MapListEntity("物资名称", dataBean.getMaterialName()));
                    mapListEntities.add(new MapListEntity("规格/型号", dataBean.getModel()));
                    mapListEntities.add(new MapListEntity("单位", dataBean.getUnit()));
                    mapListEntities.add(new MapListEntity("数量", dataBean.getQuantity()));
                    listener.upDataTextsView(mapListEntities);
                    listener.upDataRemarkView(new MapListEntity("申请原因", dataBean.getReason()));
                } else {
                    onPresenterListener.onsucced(null);
                }
            }


            @Override
            public void onFailure(String msg) {
                onPresenterListener.onsucced(null);
//                OrderGoodsMessageListener listener = (OrderGoodsMessageListener) onPresenterListener;
//                List<MapListEntity> mapListEntities = new ArrayList<>();
//                mapListEntities.add(new MapListEntity("物资名称", "摄像机"));
//                mapListEntities.add(new MapListEntity("规格/型号", "WS5241"));
//                mapListEntities.add(new MapListEntity("单位", "个"));
//                mapListEntities.add(new MapListEntity("数量", "8个"));
//                listener.upDataTextsView(mapListEntities);
//                listener.upDataRemarkView(new MapListEntity("申请原因", "摄像机坏了"));
            }
        });

    }
}
